package com.csii.branch.activity.server.impl;

import com.csii.activiti.server.abstraction.entity.ActDept;
import com.csii.activiti.server.abstraction.service.ActDeptService;
import com.csii.core.api.Result;
import com.csii.user.entity.SysDepart;
import com.csii.user.service.ISysUserBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class ActDeptServiceImpl implements ActDeptService {
    @Autowired
    private ISysUserBaseService sysUserBaseService;

    @Override
    public List<ActDept> queryDeptLikeDeptName(String deptName) {
        Result<List<SysDepart>> listResult = sysUserBaseService.queryDeptLikeDeptName(deptName);
        if (listResult != null){
            List<SysDepart> result = listResult.getResult();
            return result.stream().map(item -> new ActDept(item.getDepartName(),item.getOrgCode())).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }

    @Override
    public List<ActDept> queryDeptByDeptCodes(Set<String> deptCodes) {
        Result<List<SysDepart>> listResult = sysUserBaseService.queryDeptByDeptCodes(new ArrayList<>(deptCodes));
        if (listResult != null){
            List<SysDepart> result = listResult.getResult();
            return result.stream().map(item -> new ActDept(item.getDepartName(),item.getOrgCode())).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }
}
